import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from "vue-router";
import Login from "@/views/login/login.vue";
// 由于找不到指定的模块，暂时注释掉这些导入语句
import Error404 from "@/views/error-page/error404.vue";
import Index from "@/views/index/index.vue";
import User_Register from "@/views/register/user_register.vue"
import Logout from "@/views/login/logout.vue"
import Home_Main from '@/layout/home_main.vue'
import Workstation from '@/views/api/workstation.vue'
import Test_Plan from '@/views/api/test_plan.vue'
import Case_Management from '@/views/api/case_management.vue'
import Api_Test from '@/views/api/api_test.vue'
import TestCaseDetail from "../views/api/case_management_info/TestCaseDetail.vue"
import Bug_Management from '@/views/api/bug_management.vue'
import Workstation_Home from '@/views/api/workstation_info/workstation_home.vue'

// 本地静态路由
export const routes: Array<RouteRecordRaw> = [
	{
		path: "/",
		name: "home_page",
		component: Home_Main,
		//子路由
		children: [
			{
				path: "workstation",
				component: Workstation,
				meta: {
					title: "工作台",
				},
				children: [
					{
						path: 'home',
						component: Workstation_Home,
						meta: {
							title: '工作台首页'
						}
					}
				]
			},
			{
				path: "test-plan",
				component: Test_Plan,
				meta: {
					title: "测试计划"
				}
			},
			{
				path: "case-management",
				component: Case_Management,
				meta: {
					title: "测试用例"
				},
				children: [
					{
						path: 'detail',
						component: TestCaseDetail,
						meta: {
							title: '测试用例详情'
						}
					}
				]
			},
			{
				path: "api-test",
				component: Api_Test,
				meta: {
					title: "接口测试"
				}
			},
			{
				path: "bug-management",
				component: Bug_Management,
				meta: {
					title: "缺陷管理"
				}
			}
		]
	},
	{
		name: "login",
		path: "/login",
		component: Login,
	},
	{
		name: "logout",
		path: "/logout",
		component: Logout,
	},
	{
		name: "register",
		path: "/register",
		component: User_Register,
	},
	{
		name: "NotFound",
		path: "/:pathMatch(.*)*",
		component: Error404,
	},

];

// 默认路由，所有用户共享
const routes_new = [
	{
		path: "/",
		name: "home_page",
		component: Home_Main,
	},
	{
		name: "login",
		path: "/login",
		component: Login,
	},
	{
		name: "logout",
		path: "/logout",
		component: Logout,
	},
	{
		name: "register",
		path: "/register",
		component: User_Register,
	},
	{
		name: "NotFound",
		path: "/:pathMatch(.*)*",
		component: Error404,
	}
]

// 动态路由，用于匹配菜单动态添加路由
const asyncRoutes = [
	{}
]

// 创建路由
const router = createRouter({
	history: createWebHashHistory(),
	routes: routes,
});

export default router;

// 动态添加路由
// export function addRoutes(menus) {
// 	const findAndAddRoutesByMenu = (arr) => {
// 		arr.forEach(e => {
// 			let item = asyncRoutes.find(o => o.path == e.frontpath)
// 			if (item && router.hasRoute(item.path)) {
// 				router.addRoute('home_page', item)
// 			}
// 			if (e.children && e.children.length > 0) {
// 				findAndAddRoutesByMenu(e.children)
// 			}
// 		})
// 	}
// 	findAndAddRoutesByMenu(menus)
// 	console.log(router.getRoutes());

// }